<!DOCTYPE html>

<html lang="zh" xmlns:th="http://www.thymeleaf.org">

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta content="IE=edge" http-equiv="X-UA-Compatible">
    <link rel="icon" sizes="any" mask="" href="../static/img/boxicon.png">


    <title>Depot仓储管理系统 | 添加订单</title>
    <meta content="Depot仓储管理系统 添加订单" name="description">
    <meta content="Depot仓储管理系统 添加订单" name="keywords">


    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.6 -->
    <!-- Font Awesome -->
    <!-- Ionicons -->
    <!-- iCheck -->
    <!-- Morris chart -->
    <!-- jvectormap -->
    <!-- Date Picker -->
    <!-- Daterange picker -->
    <!-- Bootstrap time Picker -->
    <!--<link rel="stylesheet" href="../static/plugins/timepicker/bootstrap-timepicker.min.css">-->
    <!-- bootstrap wysihtml5 - text editor -->
    <!--数据表格-->
    <!-- 表格树 -->
    <!-- select2 -->
    <!-- Bootstrap Color Picker -->
    <!-- bootstrap wysihtml5 - text editor -->
    <!--bootstrap-markdown-->
    <!-- Theme style -->
    <!-- AdminLTE Skins. Choose a skin from the css/skins
       folder instead of downloading all of them to reduce the load. -->
    <!-- Ion Slider -->
    <!-- ion slider Nice -->
    <!-- bootstrap slider -->
    <!-- bootstrap-datetimepicker -->

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->


    <!-- jQuery 2.2.3 -->
    <!-- jQuery UI 1.11.4 -->
    <!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
    <!-- Bootstrap 3.3.6 -->
    <!-- Morris.js charts -->
    <!-- Sparkline -->
    <!-- jvectormap -->
    <!-- jQuery Knob Chart -->
    <!-- daterangepicker -->
    <!-- datepicker -->
    <!-- Bootstrap WYSIHTML5 -->
    <!-- Slimscroll -->
    <!-- FastClick -->
    <!-- iCheck -->
    <!-- AdminLTE App -->
    <!-- 表格树 -->
    <!-- select2 -->
    <!-- bootstrap color picker -->
    <!-- bootstrap time picker -->
    <!--<script src="../static/plugins/timepicker/bootstrap-timepicker.min.js"></script>-->
    <!-- Bootstrap WYSIHTML5 -->
    <!--bootstrap-markdown-->
    <!-- CK Editor -->
    <!-- InputMask -->
    <!-- DataTables -->
    <!-- ChartJS 1.0.1 -->
    <!-- FLOT CHARTS -->
    <!-- FLOT RESIZE PLUGIN - allows the chart to redraw when the window is resized -->
    <!-- FLOT PIE PLUGIN - also used to draw donut charts -->
    <!-- FLOT CATEGORIES PLUGIN - Used to draw bar charts -->
    <!-- jQuery Knob -->
    <!-- Sparkline -->
    <!-- Morris.js charts -->
    <!-- Ion Slider -->
    <!-- Bootstrap slider -->
    <!-- bootstrap-datetimepicker -->
    <!-- 页面meta /-->
    <link href="../static/plugins/video/video.css" rel="stylesheet" type="text/css">
    <link href="../static/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="../static/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <link href="../static/plugins/ionicons/css/ionicons.min.css" rel="stylesheet">
    <link href="../static/plugins/iCheck/square/blue.css" rel="stylesheet">
    <link href="../static/plugins/morris/morris.css" rel="stylesheet">
    <link href="../static/plugins/jvectormap/jquery-jvectormap-1.2.2.css" rel="stylesheet">
    <link href="../static/plugins/datepicker/datepicker3.css" rel="stylesheet">
    <link href="../static/plugins/daterangepicker/daterangepicker.css" rel="stylesheet">
    <link href="../static/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css" rel="stylesheet">
    <link href="../static/plugins/datatables/dataTables.bootstrap.css" rel="stylesheet">
    <link href="../static/plugins/treeTable/jquery.treetable.css" rel="stylesheet">
    <link href="../static/plugins/treeTable/jquery.treetable.theme.default.css" rel="stylesheet">
    <link href="../static/plugins/select2/select2.css" rel="stylesheet">
    <link href="../static/plugins/colorpicker/bootstrap-colorpicker.min.css" rel="stylesheet">
    <link href="../static/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css" rel="stylesheet">
    <link href="../static/plugins/adminLTE/css/AdminLTE.css" rel="stylesheet">
    <link href="../static/plugins/adminLTE/css/skins/_all-skins.min.css" rel="stylesheet">
    <link href="../static/css/style.css" rel="stylesheet">
    <link href="../static/plugins/ionslider/ion.rangeSlider.css" rel="stylesheet">
    <link href="../static/plugins/ionslider/ion.rangeSlider.skinNice.css" rel="stylesheet">
    <link href="../static/plugins/bootstrap-slider/slider.css" rel="stylesheet">
    <link href="../static/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css" rel="stylesheet">
</head>

<body class="hold-transition skin-purple sidebar-mini">
<!-- 页面头部 -->
<header class="main-header">


    <!-- Logo -->
    <a class="logo" href="/index/frontData">
        <!-- mini logo for sidebar mini 50x50 pixels -->
        <span class="logo-mini"><b>仓储</b></span>
        <!-- logo for regular state and mobile devices -->
        <span class="logo-lg"><b>Depot仓储</b>管理系统</span>
    </a>


    <!-- Header Navbar: style can be found in header.less -->
    <nav class="navbar navbar-static-top">
        <!-- Sidebar toggle button-->
        <a class="sidebar-toggle" data-toggle="offcanvas" href="#" role="button">
            <span class="sr-only">Toggle navigation</span>
        </a>

        <div class="navbar-custom-menu">
            <ul class="nav navbar-nav">
                <!-- User Account: style can be found in dropdown.less -->
                <li class="dropdown user user-menu">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                        <img alt="User Image" class="user-image" src="../static/img/user2-160x160.jpg">
                        <span class="hidden-xs" th:text="${session.user.username}">用户名</span>
                    </a>
                    <ul class="dropdown-menu">
                        <!-- User image -->
                        <li class="user-header">
                            <img alt="User Image" class="img-circle" src="../static/img/user2-160x160.jpg">

                            <p th:text="${session.user.username}">用户名</p>
                            <div style="color:#ffffff"><small>登陆时间：</small> <small th:text="${session.loginTime}">登陆时间</small>
                            </div>

                        </li>
                        <!-- Menu Body
                <li class="user-body">
                    <div class="row">
                        <div class="col-xs-4 text-center">
                            <a href="#">Followers</a>
                        </div>
                        <div class="col-xs-4 text-center">
                            <a href="#">Sales</a>
                        </div>
                        <div class="col-xs-4 text-center">
                            <a href="#">Friends</a>
                        </div>
                    </div>
                </li>-->
                        <!-- Menu Footer-->
                        <li class="user-footer">
                            <div class="pull-left">
                                <a class="btn btn-default btn-flat" href="/user/changePasswordPage">修改密码</a>
                            </div>
                            <div class="pull-right">
                                <a class="btn btn-default btn-flat" href="/user/logout">注销</a>
                            </div>
                        </li>
                    </ul>
                </li>

            </ul>
        </div>
    </nav>
</header>
<!-- 页面头部 /-->

<!-- 导航侧栏 -->
<aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
        <!-- Sidebar user panel -->
        <div class="user-panel">
            <div class="pull-left image">
                <img alt="User Image" class="img-circle" src="../static/img/user2-160x160.jpg">
            </div>
            <div class="pull-left info">
                <p th:text="${session.user.username}">用户名</p>
                <a href="#"><i class="fa fa-circle text-success"
                               th:text="'实例：'+${session.user.instanceId}+'&nbsp;&nbsp;'"></i>已登录</a>
            </div>
        </div>
        <!-- search form -->
        <!--<form action="#" method="get" class="sidebar-form">
    <div class="input-group">
        <input type="text" name="q" class="form-control" placeholder="搜索...">
        <span class="input-group-btn">
        <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i>
        </button>
      </span>
    </div>
</form>-->
        <!-- /.search form -->


        <!-- sidebar menu: : style can be found in sidebar.less -->
        <ul class="sidebar-menu">
            <li class="header">菜单</li>

            <li id="admin-index"><a href="/index/frontData"><i class="fa fa-dashboard"></i> <span>首页</span></a>
            </li>

            <!-- 菜单 -->


            <li class="treeview">
                <a href="#">
                    <i class="fa fa-archive"></i> <span>商品管理</span>
                    <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                    </span>
                </a>
                <ul class="treeview-menu">

                    <li id="product-data">
                        <a href="/product/productData">
                            <i class="fa fa-circle-o"></i> 商品详情
                        </a>
                    </li>

                    <li id="product-add">
                        <a href="/product/addProductPage">
                            <i class="fa fa-circle-o"></i> 添加商品
                        </a>
                    </li>
                </ul>
            </li>

            <li class="treeview">
                <a href="#">
                    <i class="fa fa-calendar-minus-o"></i> <span>订单管理</span>
                    <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                    </span>
                </a>
                <ul class="treeview-menu">

                    <li id="order-data">
                        <a href="/order/orderData">
                            <i class="fa fa-circle-o"></i> 订单详情
                        </a>
                    </li>

                    <li id="order-add">
                        <a href="/order/addOrderPage">
                            <i class="fa fa-circle-o"></i> 添加订单
                        </a>
                    </li>

                    <li id="order-pending">
                        <a href="/order/pendingOrderPage">
                            <i class="fa fa-circle-o"></i> 待处理订单
                        </a>
                    </li>

                    <li id="order-picking">
                        <a href="/order/myPickingOrderPage">
                            <i class="fa fa-circle-o"></i> 我的拣货中订单
                        </a>
                    </li>

                    <li id="order-wait-deliver">
                        <a href="/order/myWaitDeliverOrderPage">
                            <i class="fa fa-circle-o"></i> 我的待发货订单
                        </a>
                    </li>
                </ul>
            </li>

            <li class="treeview">
                <a href="#">
                    <i class="fa fa-university"></i> <span>货架管理</span>
                    <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                    </span>
                </a>
                <ul class="treeview-menu">

                    <li id="rack-data">
                        <a href="/rack/rackData">
                            <i class="fa fa-circle-o"></i> 货架详情
                        </a>
                    </li>

                    <li id="rack-add">
                        <a href="/rack/addRackPage">
                            <i class="fa fa-circle-o"></i> 添加货架
                        </a>
                    </li>
                </ul>
            </li>

            <li class="treeview">
                <a href="#">
                    <i class="fa fa-table"></i> <span>出入库记录管理</span>
                    <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                    </span>
                </a>
                <ul class="treeview-menu">

                    <li id="io-data">
                        <a href="/io/ioData">
                            <i class="fa fa-circle-o"></i> 出入库记录详情
                        </a>
                    </li>

                    <li id="io-add">
                        <a href="/io/addIoPage">
                            <i class="fa fa-circle-o"></i> 添加出入库记录
                        </a>
                    </li>
                </ul>
            </li>

            <li class="treeview">
                <a href="#">
                    <i class="fa fa-globe"></i> <span>供应商管理</span>
                    <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                    </span>
                </a>
                <ul class="treeview-menu">

                    <li id="vendors-data">
                        <a href="/vendors/vendorsData">
                            <i class="fa fa-circle-o"></i> 供应商详情
                        </a>
                    </li>

                    <li id="vendors-add">
                        <a href="/vendors/addVendorsPage">
                            <i class="fa fa-circle-o"></i> 添加供应商
                        </a>
                    </li>
                </ul>
            </li>

            <li class="treeview">
                <a href="#">
                    <i class="fa fa-user"></i> <span>用户管理</span>
                    <span class="pull-right-container">
                        <i class="fa fa-angle-left pull-right"></i>
                    </span>
                </a>
                <ul class="treeview-menu">

                    <li id="user-data">
                        <a href="/user/userData">
                            <i class="fa fa-circle-o"></i> 用户详情
                        </a>
                    </li>

                    <li id="user-add">
                        <a href="/user/addUserPage">
                            <i class="fa fa-circle-o"></i> 添加用户
                        </a>
                    </li>
                </ul>
            </li>

            <li id="analysis"><a href="/analysis/analysisPage"><i class="fa fa-pie-chart"></i> <span>数据分析</span></a>
            </li>


            <!-- 菜单 /-->

        </ul>
    </section>
    <!-- /.sidebar -->
</aside>
<!-- 导航侧栏 /-->

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            订单管理
            <small>管理您的订单</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-calendar-minus-o"></i> 订单管理</a></li>
            <li class="active">添加订单</li>
        </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">添加订单</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body">
                        <form role="form">
                            <!-- text input -->
                            <div class="form-group">
                                <label for="orderTime">下单时间</label>
                                <input class="form-control" id="orderTime" type="text" disabled>
                            </div>
                            <div class="form-group">
                                <label for="orderUser">下单者名称</label>
                                <input class="form-control" placeholder="请输入下单者名称" type="text" id="orderUser">
                            </div>
                            <div class="form-group">
                                <label for="orderLocation">收货地址</label>
                                <input class="form-control" placeholder="请输入收货地址" type="text" id="orderLocation">
                            </div>
                            <div class="form-group">
                                <label for="orderPhone">下单者联系电话</label>
                                <input class="form-control" id="orderPhone" placeholder="请输入下单者联系电话" type="number">
                            </div>
                        </form>
                    </div>
                    <!-- /.box-body -->
                </div>

                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">添加商品到订单中</h3>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body" id="addProductBlock">
                        <div class="row product-input-item" id="item1">
                            <div class="col-xs-4">
                                <div class="form-group">
                                    <label for="product1">商品1</label>
                                    <select class="form-control js-example-basic-single" id="product1">
                                    </select>
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <div class="form-group">
                                    <label for="count1">数量</label>
                                    <input class="form-control" placeholder="请输入商品数量" type="number" id="count1">
                                </div>
                            </div>
                            <div class="col-xs-4">
                                <button onclick="deleteProductInput(1)" class="btn btn-danger" style="margin-top: 25px" id="deletebtn1">删除商品</button>
                            </div>
                        </div>
                    </div>

                    <!-- /.box-body -->
                    <div class="box-footer">
                        <button onclick="addProductInput()" class="btn btn-success">增加商品</button>
                        <button onclick="add()" class="btn btn-primary">提交订单</button>
                        <button onclick="deleteAllProductInput()" class="btn btn-danger pull-right">清空商品</button>
                        <div style="margin-top: 20px">
                            <p class="alert alert-danger hidden" id="message">message</p>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.col -->
        </div>
        <!-- /.row -->
    </section>
    <!-- /.content -->

    <!-- 模态框 -->
    <div class="modal fade" id="myModal">
        <div class="modal-dialog modal-sm">
            <div class="modal-content">

                <!-- 模态框头部 -->
                <div class="modal-header">
                    <h4 class="modal-title">提示</h4>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>

                <!-- 模态框主体 -->
                <div class="modal-body">
                    模态框内容..
                </div>

                <!-- 模态框底部 -->
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">关闭</button>
                </div>

            </div>
        </div>
    </div>

</div>
<!-- /.content-wrapper -->


<!-- page script -->
<script src="../static/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="../static/plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="../static/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="../static/plugins/raphael/raphael-min.js"></script>
<script src="../static/plugins/morris/morris.min.js"></script>
<script src="../static/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="../static/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="../static/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="../static/plugins/knob/jquery.knob.js"></script>
<script src="../static/plugins/daterangepicker/moment.min.js"></script>
<script src="../static/plugins/daterangepicker/daterangepicker.js"></script>
<script src="../static/plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
<script src="../static/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="../static/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="../static/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="../static/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="../static/plugins/fastclick/fastclick.js"></script>
<script src="../static/plugins/iCheck/icheck.min.js"></script>
<script src="../static/plugins/adminLTE/js/app.min.js"></script>
<script src="../static/plugins/treeTable/jquery.treetable.js"></script>
<script src="../static/plugins/select2/select2.full.min.js"></script>
<script src="../static/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="../static/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
<script src="../static/plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
<script src="../static/plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
<script src="../static/plugins/bootstrap-markdown/js/markdown.js"></script>
<script src="../static/plugins/bootstrap-markdown/js/to-markdown.js"></script>
<script src="../static/plugins/ckeditor/ckeditor.js"></script>
<script src="../static/plugins/input-mask/jquery.inputmask.js"></script>
<script src="../static/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="../static/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="../static/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="../static/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="../static/plugins/chartjs/Chart.min.js"></script>
<script src="../static/plugins/flot/jquery.flot.min.js"></script>
<script src="../static/plugins/flot/jquery.flot.resize.min.js"></script>
<script src="../static/plugins/flot/jquery.flot.pie.min.js"></script>
<script src="../static/plugins/flot/jquery.flot.categories.min.js"></script>
<script src="../static/plugins/ionslider/ion.rangeSlider.min.js"></script>
<script src="../static/plugins/bootstrap-slider/bootstrap-slider.js"></script>
<script src="../static/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="../static/plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script charset="UTF-8" src="../static/plugins/video/pingzi_video.js" type="text/javascript"></script>
<script>
    function setFormattedTime() {
        var d = new Date();
        var month = d.getMonth()+1;
        var newMonth = month>9?month:"0"+month;
        var day = d.getDate();
        var newDay = day>9?day:"0"+day;
        var hours =d.getHours();
        var newHours = hours>9?hours:"0"+hours;
        var minutes =d.getMinutes();
        var newMinutes = minutes>9?minutes:"0"+minutes;
        var seconds =d.getSeconds();
        var newSeconds = seconds>9?seconds:"0"+seconds;
        var time = d.getFullYear()+'-'+newMonth+'-'+newDay+' '+newHours+':'+newMinutes+':'+newSeconds;
        $("#orderTime").val(time);
    }
    setFormattedTime();
    setInterval(()=>{
        setFormattedTime();
    },1000);
</script>
<script>
    let message = document.getElementById("message");
    var i=2;
    function addProductInput() {
        var addProductBlock = document.getElementById("addProductBlock");
        var divElement = document.createElement("div");
        divElement.className = "row product-input-item";
        divElement.id = "item"+i;
        divElement.innerHTML = "<div class=\"col-xs-4\">\n" +
            "                                <div class=\"form-group\">\n" +
            "                                    <label for=\"product"+i+"\">商品"+i+"</label>\n" +
            "                                    <select class=\"form-control js-example-basic-single\" id=\"product"+i+"\">\n" +
            "                                    </select>\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                            <div class=\"col-xs-4\">\n" +
            "                                <div class=\"form-group\">\n" +
            "                                    <label for=\"count"+i+"\">数量</label>\n" +
            "                                    <input class=\"form-control\" placeholder=\"请输入商品数量\" type=\"number\" id=\"count"+i+"\">\n" +
            "                                </div>\n" +
            "                            </div>\n" +
            "                            <div class=\"col-xs-4\">\n" +
            "                                <button onclick=\"deleteProductInput("+i+")\" class=\"btn btn-danger\" style=\"margin-top: 25px\" id=\"deletebtn"+i+"\">删除商品</button>\n" +
            "                            </div>";
        i++;
        addProductBlock.appendChild(divElement);
        $('.js-example-basic-single').select2({
            width: "26vw",
            data: data
        });
        $(".main-sidebar").css("minHeight",document.body.scrollHeight+"px");
    }

    function deleteProductInput(index) {
        if(i===2){
            $(".modal-body").html("订单必须含有至少一个商品！");
            $("#myModal").modal('show');
            return;
        }
        let elementId = "item"+index;
        $("#"+elementId).remove();
        for(let j=index+1;j<i;j++){
            let newIndex=j-1;
            $("#product"+j).prev().attr("for","product"+newIndex);
            $("#product"+j).prev().html("商品"+newIndex);
            $("#count"+j).prev().attr("for","count"+newIndex);
            $("#deletebtn"+j).attr("onclick","deleteProductInput("+newIndex+")");
            $("#item"+j).attr("id","item"+newIndex);
            $("#product"+j).attr("id","product"+newIndex);
            $("#count"+j).attr("id","count"+newIndex);
            $("#deletebtn"+j).attr("id","deletebtn"+newIndex);
        }
        i--;
        $(".main-sidebar").css("minHeight",document.body.scrollHeight+"px");
    }

    function deleteAllProductInput(){
        $(".product-input-item").remove();
        i=1;
        addProductInput();
    }

    var data = []

    $(document).ready(function () {
        // 激活导航位置
        setSidebarActive("order-add");

        $.ajax({
            type: "post",
            url: "/product/getSelection",
            success: function (response) {
                if (response["status"] === 200) {
                    data = response["data"];
                    $('.js-example-basic-single').select2({
                        width: "26vw",
                        data: data
                    });
                }
            },
        });

        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });


    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }

    $(function () {
        $("#example1").DataTable();
        $('#example2').DataTable({
            "paging": true,
            "lengthChange": false,
            "searching": false,
            "ordering": true,
            "info": true,
            "autoWidth": false
        });
    });

    var orderUser = document.getElementById("orderUser");
    var orderLocation = document.getElementById("orderLocation");
    var orderPhone = document.getElementById("orderPhone");
    function add() {
        let orderProductList = [];//构造订单物品列表
        let idList = [];//id列表（用于检查是否重复
        var submitFlag = true;//提交标志
        for (let num = 1; num < i && submitFlag; num++) {
            let productId = document.getElementById("product" + num).value;
            let count = document.getElementById("count" + num).value;
            if (count === "" && submitFlag) {
                //若有订购数量为空
                message.innerText = "请输入订购数量";
                message.setAttribute("class", "alert alert-danger");
                submitFlag = false;
                return;
            }
            else if (idList.includes(productId) && submitFlag) {
                //若有重复商品
                message.innerText = "请删除重复商品";
                message.setAttribute("class", "alert alert-danger");
                submitFlag = false;
                return;
            }
            else {
                message.setAttribute("class", "alert alert-danger hidden");
                idList.push(productId);
                orderProductList.push({
                    "productId": productId,
                    "count": count,
                });
            }
        }
        if (submitFlag) {
            $.ajax({
                url: "/order/add",
                type: "post",
                contentType: 'application/json',
                data: JSON.stringify({
                    "order": {
                        "orderUser": orderUser.value,
                        "orderLocation": orderLocation.value,
                        "orderPhone": orderPhone.value,
                    },
                    "orderProductList": orderProductList,
                }),
                success: function (msg) {
                    if (msg['status'] === 200) {
                        window.location.href = "/order/orderData";
                    } else {
                        alert(msg['error'])
                    }
                }
            })
        }
    }
</script>
</body>


</html>